/*
 * Created on Oct 22, 2003
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.history;

import org.vectrics.common.db.JdbcTarget;
import org.vectrics.common.db.ProcessException;
import java.sql.ResultSet;
import java.util.List;
import org.apache.log4j.Logger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;


public class FindTransactionsJdbc implements JdbcTarget {
	private transient static Logger log = Logger.getLogger(FindTransactionsJdbc.class);
	private static SimpleDateFormat sqlDateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private String queryStr = "";
	private Vector txIds = new Vector();


	public FindTransactionsJdbc(String userNameWhoDidAction, Date startDate, Date endDate) {                	
		String whereClause = " where";
		whereClause += " (oh.date >= '" + sqlDateFormat.format(startDate) + "')";
		whereClause += " and (oh.date <= '" + sqlDateFormat.format(endDate) + "')";
		if (userNameWhoDidAction != null) {
			whereClause += " and (user_name = '" + userNameWhoDidAction + "')";
		}
        
		queryStr = "select oh.uid"
				+ " from object_history" 
				+ whereClause;
		if (log.isDebugEnabled()) {
			log.debug("query = " + queryStr);
		}
	}
	

	public List getTxIds() {
		return(txIds);
	}
	
	
	public void processResults(ResultSet results) throws ProcessException {
		try {
			while (results.next()) {
				String id = results.getString("uid");
				txIds.add(id);
			}
		}
		catch (java.sql.SQLException se) {
			log.error("processResults() - SQL Exception while processing results list", se);
		}
	}

	
	public String getQuery() {
		return(queryStr);		
	}
}

